package cn.colins.raft.rpc;

import cn.colins.raft.rpc.future.RpcWriteFuture;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: raft-java-demo
 * @description:
 * @author: colins
 * @create: 2023-07-15 23:28
 **/
public class RpcRemoteContext {

    /**
     * netty同步响应缓存
     */
    public static Map<String, RpcWriteFuture> CLIENT_REQUEST_CACHE = new ConcurrentHashMap<>(1024);


    public static void addRequestCache(String requestId, RpcWriteFuture writeFuture) {
        CLIENT_REQUEST_CACHE.put(requestId, writeFuture);
    }

    public static RpcWriteFuture getRequestCache(String requestId) {
        return CLIENT_REQUEST_CACHE.get(requestId);
    }

    public static void removeRequestCache(String requestId) {
        CLIENT_REQUEST_CACHE.remove(requestId);
    }
}
